package com.yidu.hbats.service.impl.atsData;

import com.yidu.hbats.dao.AtsBaseSportItemMapper;
import com.yidu.hbats.dao.AtsBaseSportMapper;
import com.yidu.hbats.model.AtsBaseSport;
import com.yidu.hbats.model.AtsBaseSportItem;
import com.yidu.hbats.service.atsBase.AtsBaseSportItemService;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 批次service
 * auto:ltx
 */
public class AtsDataBatchImpl {
    //项目指标dao
    @Resource
    private AtsBaseSportItemMapper atsBaseSportItemMapper;
    //体育项目dao
    @Resource
    private AtsBaseSportMapper atsBaseSportMapper;
    //项目指标Service
    @Resource
    private AtsBaseSportItemService atsBaseSportItemService;

    /**
     * 删除
     * @param sportId
     * @return
     */
    public int deleteByPrimaryKey(Integer sportId) {
        return atsBaseSportMapper.deleteByPrimaryKey(sportId);
    }

    /**
     * 新增
     * @param record
     * @param itemIds
     * @return
     */
    public int insert(AtsBaseSport record,String itemIds,String jihuaIds) {
        //调用新增体育项目方法
        atsBaseSportMapper.insert(record);
        //分割测试指标
        String[] id = itemIds.split(",");
        List<AtsBaseSportItem> list = new ArrayList<>();

        for (int i = 0; i < id.length ; i++) {
            AtsBaseSportItem atsBaseSportItem = new AtsBaseSportItem();
            atsBaseSportItem.setSportId(record.getSportId());
            atsBaseSportItem.setItemId(Integer.parseInt(id[i]));
            atsBaseSportItem.setCreatTime(new Date());
            atsBaseSportItem.setCreater(record.getCreater());
            atsBaseSportItem.setIsva(1);
            //atsBaseSportItemService.insert(atsBaseSportItem);
            //加入集合
            list.add(atsBaseSportItem);
        }
        //分割计划指标ID
        String[] id2 = jihuaIds.split(",");
        List<AtsBaseSportItem> list2 = new ArrayList<>();
        for (int i = 0; i < id2.length ; i++) {
            AtsBaseSportItem atsBaseSportItem = new AtsBaseSportItem();
            atsBaseSportItem.setSportId(record.getSportId());
            atsBaseSportItem.setItemId(Integer.parseInt(id2[i]));
            atsBaseSportItem.setCreatTime(new Date());
            atsBaseSportItem.setCreater(record.getCreater());
            atsBaseSportItem.setIsva(2);
            //加入集合
            list2.add(atsBaseSportItem);
        }

        //新增
        int count = atsBaseSportMapper.insert(record);
        //long end = System.currentTimeMillis();
        //返回结果
        return count;
    }

    /**
     * 新增
     * @param record
     * @return
     */
    public int insertSelective(AtsBaseSport record) {
        return atsBaseSportMapper.insertSelective(record);
    }

    /**
     * 根据ID查询
     * @param sportId
     * @return
     */
    public AtsBaseSport selectByPrimaryKey(Integer sportId) {
        return atsBaseSportMapper.selectByPrimaryKey(sportId);
    }

    /**
     * 修改
     * @param record
     * @return
     */
    public int updateByPrimaryKeySelective(AtsBaseSport record) {
        return atsBaseSportMapper.updateByPrimaryKeySelective(record);
    }

    /**
     * 修改
     * @param record 体育项目
     * @param atsBaseSportItems 测试指标
     * @param atsBaseSportItems2 计划指标
     * @return
     */
    public int updateByPrimaryKey(AtsBaseSport record, List<AtsBaseSportItem> atsBaseSportItems,List<AtsBaseSportItem> atsBaseSportItems2) {
        int count = atsBaseSportMapper.updateByPrimaryKey(record);
        return count;
    }

    /**
     * 查询所有
     * @param page 页数
     * @param limit 显示行数
     * @param sportName 项目名称
     * @return
     */
    public List<AtsBaseSport> selectAll(Integer page,Integer limit,String sportName) {
        AtsBaseSport atsBaseSport = new AtsBaseSport();
        atsBaseSport.setSportName(sportName);
        return atsBaseSportMapper.selectAll(atsBaseSport);
    }


    /**
     * 查询所有
     * @return
     */
    public List<AtsBaseSport> findAll() {
        return atsBaseSportMapper.findAll();
    }

    /**
     * 查询总行数
     * @param sportName
     * @return
     */
    public Integer count(String sportName) {
        AtsBaseSport atsBaseSport = new AtsBaseSport();
        atsBaseSport.setSportName(sportName);
        return atsBaseSportMapper.selectCount(atsBaseSport);
    }

    /**
     * 根据人员Id查询体育项目
     * @param athleteId
     * @return
     */
    public AtsBaseSport selectAth(Integer athleteId) {
        return atsBaseSportMapper.selectAth(athleteId);
    }

    /**
     * 查询教练所属项目
     * @param coachId 教练Id
     * @return
     */

    public AtsBaseSport selectCoachSport(Integer coachId) {
        return atsBaseSportMapper.selectCoachSport(coachId);
    }

    /**
     * 查询专家项目
     * @param experId 专家Id
     * @return
     */
    public AtsBaseSport selectExpertSport(Integer experId) {
        return atsBaseSportMapper.selectExpertSport(experId);
    }

    /**
     * 删除
     * @param sportId 项目ID
     * @return
     */
    public int deleteUtis(Integer sportId){
        return atsBaseSportMapper.deleteByPrimaryKey(sportId);
    }
}
